﻿@{
    ViewBag.Title = "RoadFlow";
    Page.BodyStyle = "class='mainBody'";
    Page.CheckApp = false;
}
<style type="text/css">
    html,body {overflow:hidden; }
</style>
<div class="mainTop">
    <div class="mainTopLeft"></div>
    <div class="mainTopRight">
        <div style="height:18px;"></div>
        <div style="padding-right:20px;">
            <div>
                <span class="indexwelcome">欢迎您：@ViewBag.UserName</span>
                <span style="margin-right:6px;"></span>
                <span style="margin-right:6px;">日期：<span id="CurrentDateTimeSpan">@ViewBag.DateTime</span></span>
                <span style="">主题：</span>
                <span class="mainTheme_bluelight" onclick="changeTheme('BlueLight', true);"></span>
                <span class="mainTheme_blue" onclick="changeTheme('Blue', true);"></span>
                <span class="mainTheme_green" onclick="changeTheme('Green', true);"></span>
                <span class="mainTheme_gray" onclick="changeTheme('Gray', true);"></span>
            </div>
            <div style="margin-top:8px;">
                <span style="margin-right:6px;"><a href="javascript:void(0);" onclick="openApp('Home/Home',0,'首页','index'); return false;" class="white" >首&nbsp;&nbsp;页</a></span>
                <span style="margin-right:6px;">|</span>
                <span style="margin-right:6px;"><a href="javascript:void(0);" onclick="openApp('Members/EditPass',2,'修改密码','index_editpass',500,210); return false;" class="white" >修改密码</a></span>
                <span style="margin-right:6px;">|</span>
                <span style="margin-right:4px;"><a href="javascript:void(0);" onclick="if(confirm('您真的要退出系统吗?')){window.location='Login/Quit';} return false;" class="white" >退出系统</a></span>
            </div>
        </div>
    </div>
    <div style="clear:both;"></div>
</div>
<div class="mainDiv">
<table cellpadding="0" cellspacing="0" width="100%" border="0" style="table-layout:fixed;">
    <tr>
        <td class="mainMenutd" id="mainMenutd" >
            <div class="menuDiv1" onclick="switchMenu(false);"></div>
            <div class="menuDiv">
                <div class="menuDivTitle">
                    <div class="menuDivTitlel">管理目录</div>
                    <div class="menuDivTitler" onclick="switchMenu(true);"></div>
                </div>
                    
                <div style="padding:0 4px 0 8px;" id="RoleDiv" runat="server">
                    <select class="myselect" style="width:135px; height:24px; margin-top:4px;" id="MyRole" name="MyRole" onchange="roleChange(this.value);">
                        @Html.Raw(ViewBag.RolesOptions)
                    </select>
                </div>
                <div id="treeDiv" style="margin:0; overflow:auto;  padding:3px 3px 0 4px; "></div>
            </div>
        </td>
        <td class="mainSplittd" id="mainSplittd"></td>
        <td style="vertical-align:top;">
            <div id="mainTabDiv" class="mainTabDiv"></div>
        </td>
    </tr>
</table>
</div>
<script type="text/javascript">
    var mainTab = null;
    var mainTree = null;
    var mainDialog = new RoadUI.Window();
    var defaultRoleID = "@ViewBag.DefaultRoleID";
    var currentDateTimeSpan = $("#CurrentDateTimeSpan");
    var rolesLength = @ViewBag.RoleLength;
    var userID = '@Business.Platform.Users.CurrentUserID';
    var rootdir = '@Url.Content("~/")';
    $(function ()
    {
        rootdir = "/" == rootdir ? "" : rootdir;
        if (rolesLength <= 1)
        {
            $("#MyRole").hide();
        }

        $('#mainTabDiv').height($(window).height() - 75);
        $('#treeDiv').height($(window).height() - (rolesLength > 1 ? 133 : 104));

        $(window).bind('resize', function ()
        {
            $('#mainTabDiv').height($(window).height() - 75);
            $('#treeDiv').height($(window).height() - (rolesLength > 1 ? 133 : 104));
            mainTab.topResize($(window).height() - 101);
        });

        mainTab = new RoadUI.Tab({ id: "mainTabDiv", replace: true });
        roleChange(defaultRoleID);
        openApp("Home/Home", 0, "首页", "index");

        //初始化主题按钮样式
        var theme = $.cookies.get("theme_platform") || "BlueLight";
        changeTheme(theme, false);
    });

    function update()
    {
        $.ajax({ url: "", cache: false, async: true, success: function (txt)
        {
            currentDateTimeSpan.html(txt);
            window.setTimeout(update, 10000);
        },
            error: function ()
            {
                window.setTimeout(update, 20000);
            }
        });
    }

    function treeClick(json)
    {
        if (json)
        {
            openApp(json.link, json.model, json.title, json.id, parseInt(json.width), parseInt(json.height), true);
        }
    }

    function openApp(url, model, title, id, width, height, isAppendParams)
    {
        if (!url || url.toString().length == 0)
        {
            return;
        }
        if (!id)
        {
            id = RoadUI.Core.newid();
        }
        if (width == 0) width = undefined;
        if (height == 0) height = undefined;
        if (isAppendParams)
        {
            url += url.indexOf('?') >= 0 ? "&appid=" + id : "?appid=" + id;
        }
        url = rootdir + url;
       
        switch (parseInt(model))
        {
            case 0:
                mainTab.addTab({ id: "tab_" + id.replaceAll('-', ''), title: title, src: url });
                break;
            case 1:
                mainDialog.open({ id: "window_" + id.replaceAll('-', ''), title: title, url: url, width: width || 800, height: height || 460, ismodal: false });
                break;
            case 2:
                mainDialog.open({ id: "window_" + id.replaceAll('-', ''), title: title, url: url, width: width || 800, height: height || 460, ismodal: true });
                break;
            case 3:
                RoadUI.Core.open(url,width || 800,height || 460, title);
                break;
            case 4:
                window.showModalDialog(url,null,"dialogWidth="+(width || 800)+"px;dialogHeight="+(height || 460)+"px;center=1");
                break;
            case 5:
                window.open(url);
                break;
        }
    }

    function switchMenu(flag)
    {
        if (flag)
        {
            $("#mainMenutd").removeClass().addClass("mainMenutd1");
            $(".menuDiv").hide(200);
            $(".menuDiv1").show(100);
        }
        else
        {
            $("#mainMenutd").removeClass().addClass("mainMenutd");
            $(".menuDiv").show();
            $(".menuDiv1").hide();
        }
    }

    function roleChange(roleID)
    {
        $("#treeDiv").html("");
        mainTree = new RoadUI.Tree({ id: "treeDiv", path: rootdir + "Home/Menu?roleid=" + roleID + "&userid=" + userID, refreshpath: rootdir + "Home/MenuRefresh?roleid=" + roleID + "&userid=" + userID, showroot: true, onclick: treeClick });
    }

    function changeTheme(themeName, isCng)
    {
        if (!themeName || themeName.toString().trim().length == 0)
        {
            themeName = $.cookies.get("theme_platform")
        }

        $("span[class^='mainTheme_']").each(function ()
        {
            var cssName = $(this).attr("class");
            $(this).removeClass().addClass(cssName.replace("1", ""));
            
        });
        try
        {
            themeName=themeName.toLowerCase();
            var current=$(".mainTheme_" + themeName)||$(".mainTheme_" + themeName+"1");
            current.removeClass().addClass("mainTheme_" + themeName + "1");
        }
        catch(e){}
        if(isCng)
        {
            RoadUI.Core.allFrames = [];
            RoadUI.Core.getAllFrames();
            for (var i = 0; i < RoadUI.Core.allFrames.length; i++)
            {
                $("#style_style", RoadUI.Core.allFrames[i].document).attr("href", rootdir + "/Content/Theme/" + themeName + "/Style/style.css");
                $("#style_ui", RoadUI.Core.allFrames[i].document).attr("href", rootdir + "/Content/Theme/" + themeName + "/Style/ui.css");
                //$("#style_form", iframes[i].document).attr("href", rootdir + "/Platform/WorkFlow/FormDesigner/Forms/Public/flowform_" + themeName + ".css");
            }
            $.cookies.set("theme_platform", themeName, { expiresAt: new Date(2099, 1, 1) });
        }
    }
</script>

